package com.silverbox.sweeporder.controller.thread;

import java.util.Map;

import com.silverbox.core.util.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.silverbox.core.result.CoreResponse;
import com.silverbox.core.util.HttpUtils;

/**
 * @author ywc	通用线程
 */

public class CommonThread implements Runnable {
	private static Logger logger = LoggerFactory.getLogger(CommonThread.class);
	private String tip;
	private String url;
	private Object params;
	
	public CommonThread() {
		
	}

	public CommonThread(String tip, String url, Object params) {
		super();
		this.tip = tip;
		this.url = url;
		this.params = params;
	}

	public void run() {
	    if(params instanceof Map){
            CoreResponse reStr = HttpUtils.doPostForm(url, (Map)params, 360000, 360000, "UTF-8");
            logger.info(tip+reStr);
        }else if(params instanceof String){
            String response = HttpUtil.buildJsonRequest(url, (String)params, 360000, 360000, "UTF-8");
            logger.info(tip+response);
        }
	}
	
	public static void execute(String tip,String commonThreadUtil_URL,Map params) {
		CommonThread baseUrl = new CommonThread(tip,commonThreadUtil_URL, params);
	    Thread baseThread = new Thread(baseUrl);
	    baseThread.start();
	}

    public static void execute(String tip,String commonThreadUtil_URL,String params) {
        CommonThread baseUrl = new CommonThread(tip,commonThreadUtil_URL, params);
        Thread baseThread = new Thread(baseUrl);
        baseThread.start();
    }
}
